﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_VehicleController : BaseApiController
    {
        #region DI

        public PB_VehicleController(IPB_VehicleBusiness pB_VehicleBus)
        {
            _pB_VehicleBus = pB_VehicleBus;
        }

        IPB_VehicleBusiness _pB_VehicleBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_VehicleDTO>> GetDataList(PageInput<PB_VehicleConditonDTO> input)
        {
            return await _pB_VehicleBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<PB_Vehicle> GetTheData(IdInputDTO input)
        {
            return await _pB_VehicleBus.GetTheDataAsync(input.id);
        }

        /// <summary>
        /// 根据货运公司ID查找车牌ID
        /// </summary>
        /// <param name="SupplierId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<PB_Vehicle>> GetVehicleDataList(string SupplierId)
        {
            return await _pB_VehicleBus.GetTheDatabySupplier(SupplierId);
        }


        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_Vehicle data)
        {
           
            if (data.Id.IsNullOrEmpty())
            {
               
              
                await _pB_VehicleBus.AddDataAsync(data);
            }
            else
            {
                await _pB_VehicleBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_VehicleBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}